#include "head.h"
Shape::Shape()
{
	x = 0;
	y = 0;
}
void Shape::offsetToNewXY(int newX, int newY)
{
	x = newX;
	y = newY;
}
void Shape::setXY()
{

	cin >> x >> y;
}
Rhombus::Rhombus(){
	weight = 0;
	height = 0;
}
Rhombus::Rhombus(int newX, int newY, int newWeight, int newHeight){
	x = newX;
	y = newY;
	weight = newWeight;
	height = newHeight;
}
string Rhombus::Type()
{
	return "Rhombus";
}
vector<int> Rhombus::getProperties()
{
	vector<int> tmp;
	tmp.push_back(x);
	tmp.push_back(y);
	tmp.push_back(weight);
	tmp.push_back(height);
	return tmp;
}
void Rhombus::setProperties()
{

	cin >> weight >> height;
}
void Rhombus::printProperties()
{

	cout << " weight-" << weight << " height-" << height << " x-" << x << " y-" << y << " type-" << Type() << endl;
}
Triangle::Triangle(){
	weight = 0;
	height = 0;
}
Triangle::Triangle(int newX, int newY, int newWeight, int newHeight){
	x = newX;
	y = newY;
	weight = newWeight;
	height = newHeight;
}
string Triangle::Type()
{
	return "Triangle";
}
vector<int> Triangle::getProperties()
{
	vector<int> tmp;
	tmp.push_back(x);
	tmp.push_back(y);
	tmp.push_back(weight);
	tmp.push_back(height);
	return tmp;
}
void Triangle::setProperties()
{

	cin >> weight >> height;
}
void Triangle::printProperties()
{

	cout << " weight-" << weight << " height-" << height << " x-" << x << " y-" << y << " type-" << Type() << endl;
}
Circle::Circle(){
	radius = 0;

}
Circle::Circle(int newX, int newY, int newRadius){
	x = newX;
	y = newY;
	radius = newRadius;

}
string Circle::Type()
{
	return "Circle";
}
vector<int> Circle::getProperties()
{
	vector<int> tmp;
	tmp.push_back(x);
	tmp.push_back(y);
	tmp.push_back(radius);

	return tmp;

}
void Circle::setProperties()
{

	cin >> radius;
}
void Circle::printProperties()
{

	cout << " radius-" << radius << " x-" << x << " y-" << y << " type-" << Type() << endl;
}

void Container::addFigure(Shape * newFigure)
{
	shapes.push_back(newFigure);
}
void Container::deleteFigure(int i)
{
	shapes.erase(shapes.begin() + i - 1);
}
void Container::moveToNewXY(int newX, int newY, int i)
{
	shapes.at(i)->offsetToNewXY(newX, newY);
}
void Container::setProperties(int i)
{
	shapes.at(i)->setProperties();

}
void Container::saveFile()
{
	ofstream file("output.txt");
	for (int i = 0; i < shapes.size(); i++)
	{
		vector<int> tmp = shapes.at(i)->getProperties();
		file << shapes.at(i)->Type()[0]<<endl;
		for (int j = 0; j < tmp.size(); j++)
		{

			file << tmp.at(j) << endl;
		}
	}

	file.close();
}
void Container::loadFile()
{
	ifstream file("output.txt");
	if (file.is_open())
	{
		while (true) {
			if (file.eof()) { break; }
			else{

			char tmp;
			file >> tmp;
			if (!file.good())
				break;
			Shape *figure;
			switch (tmp)
			{
			case 'R':{
				int x, y, weight, height;
				file >> x >> y >> weight >> height;
				figure = new Rhombus(x, y, weight, height);
				break; }
			case 'T':{
				int x, y, weight, height;
				file >> x >> y >> weight >> height;
				figure = new Triangle(x, y, weight, height);
				break; }
			case 'C':{
				int x, y, radius;
				file >> x >> y >> radius;
				figure = new Circle(x, y, radius);
				break; }
			}

			shapes.push_back(figure);} 
		}
	}
	file.close();
}
void Container::printShapes()
{
	for (int i = 0; i < shapes.size(); i++)
		shapes.at(i)->printProperties();
}
void check()
{
	int x, y,height,weight;
	char type;
	Container a, b;
	while (true)
	{ 
		cout << "Add figure? \'1\' - yes \'0\' -  no\n";
		int i = 0;
		cin >> i;
		if (i == 0)
			break;
		Shape *figure = NULL;
		cout << "What type do you need \'T\' - Triangle \'R\' - Rhombus \'C\' - Circle\n";
		cin >> type;
		switch (type)
		{
		case 'T':{cout << "Endter x:"; cin >> x; 
				  cout << "Endter y:"; cin >> y; 
				  cout << "Endter height:"; cin >> height; 
				  cout << "Endter weight:"; cin >> weight;   
				  figure = new Triangle(x, y, height, weight); 
				  break; 
		}
		case 'R':{cout << "Endter x:"; cin >> x;
				  cout << "Endter y:"; cin >> y;
				  cout << "Endter height:"; cin >> height;
				  cout << "Endter weight:"; cin >> weight;   
				  figure = new Rhombus(x, y, height, weight); 
				  break; 
		}
		case 'C':{cout << "Endter x:"; cin >> x;
				  cout << "Endter y:"; cin >> y;
				  cout << "Endter radius:"; cin >> height;
				  figure = new Circle(x, y, height); 
				  break; 
		}
		default:
			break;
		}
		a.addFigure(figure);
	}
	a.saveFile();
	a.printShapes();
	b.loadFile();
	b.printShapes();
	cin.get();
	cin.get();
}
void main()
{
	
}